package UI;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/*
* 这里是主界面UI的布局
* 有* 个人信息 添加好友 加入群聊 好友列表 群聊列表 其他消息(拓展)
* 每次添加完新组件以后一定要加上this.getContentPane().add(组件名)!!

 */
public class HomeUI extends JFrame implements MouseListener {
    //创建组件
    JButton personalInfo = new JButton("个人信息");
    JButton friendList = new JButton("好友列表");
    JButton groupList = new JButton("群聊列表");
    JButton otherMessage = new JButton("其他消息");
    public HomeUI(){
        WholeUI wholeUI = new WholeUI(this) {
            @Override
            protected void elseWindow(JFrame jFrame) {
                jFrame.setTitle("主界面");
                jFrame.setSize(800,600);
            }

        };
        loadUI();
    }

    private void loadUI() {
        // 位置大小

        personalInfo.setBounds(0,0,100,50);


        friendList.setBounds(0,150,100,50);


        groupList.setBounds(0,200,100,50);


        otherMessage.setBounds(0,250,100,50);
        //添加组件
        this.getContentPane().add(personalInfo);
        this.getContentPane().add(friendList);
        this.getContentPane().add(groupList);
        this.getContentPane().add(otherMessage);
        //添加监听
        personalInfo.addMouseListener(this);
        friendList.addMouseListener(this);
        groupList.addMouseListener(this);
        otherMessage.addMouseListener(this);
    }

    //鼠标事件(个人信息  好友列表 群聊列表 其他消息)
    @Override
    public void mouseClicked(MouseEvent e) {
        if(e.getSource()==personalInfo){
            PersonalInformationUI personalInformationUI = new PersonalInformationUI();
            this.dispose();
        }else if(e.getSource()==friendList){
            FriendListUI friendListUI = new FriendListUI();
            this.dispose();
        }else if(e.getSource()==groupList){
            GroupListUI groupListUI = new GroupListUI();
            this.dispose();
        } else if (e.getSource()==otherMessage) {
            OtherMessageUI otherMessageUI = new OtherMessageUI();
            this.dispose();

        }

    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }
}
